package com.eugene.enums;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.eugene.interfaces.Calculable;

public enum EReturnType {
	ASIS,
	LOG_RETURN{
		public <T extends Calculable> void calculateReturn(List<T> list,int timeHorizon, List<T> rst){
			if(list.size() <= timeHorizon){
				logger.warn("There are not sufficient data to calculate log Rate. Return 0");
			}
			else{
				for(int i =0 ; i<list.size()-timeHorizon; i++){
//					logger.debug("Test000:{},{}",list.get(i).getValue(),rst.get(i).getValue());
					rst.get(i).setValue(Math.log(list.get(i).getValue() / list.get(i+timeHorizon).getValue()));
//					logger.debug("Test000:{},{}", rst.get(i).getValue());
				}
			}
		}
	},
	PERCENT_RETURN{
		public <T extends Calculable> void calculateReturn(List<T> list,int timeHorizon, List<T> rst){
			double rate;
			if(list.size() <= timeHorizon){
				logger.warn("There are not sufficient data to calculate log Rate. Return 0");
			}
			
			else{
				for(int i =0 ; i<list.size()-timeHorizon; i++){
//					logger.debug("Test000:{},{}",list.get(i).getValue(),rst.get(i).getValue());
					rate = (list.get(i).getValue()-list.get(i+timeHorizon).getValue())
													/ list.get(i+timeHorizon).getValue();
					rst.get(i).setValue(rate);
//					logger.debug("Test000:{},{}", rst.get(i).getValue());
				}
			}
		}
	},
	DIFF_RETURN{
		public <T extends Calculable> void calculateReturn(List<T> list,int timeHorizon, List<T> rst){
			if(list.size() <= timeHorizon){
				logger.warn("There are not sufficient data to calculate log Rate. Return 0");
			}
			
			else{
				for(int i =0 ; i<list.size()-timeHorizon; i++){
//					logger.debug("Test000:{},{}",list.get(i).getValue(),rst.get(i).getValue());
					rst.get(i).setValue(list.get(i).getValue() - list.get(i+timeHorizon).getValue());
//					logger.debug("Test000:{},{}", rst.get(i).getValue());
				}
			}	
		}
	}
	;
	
	private final static Logger logger = LoggerFactory.getLogger(EReturnType.class);	
	

//	private EReturnType() {
//	}
	
	public <T extends Calculable> void calculateReturn(List<T> list,int timeHorizon, List<T> rst){
		
	}
//	public <T extends Calculable> List<T> calcuateReturn(List<T> list,int timeHorizon){
//		List<T> rst = new ArrayList<T>();
//		T temp = new Calculable();
//		temp.setValue(0.0);
//		return rst;
//	}
}
